// pages/collect/index.js
Page({
  data: {
    collections: [
      {
        id: 1,
        type: "guide",
        title: "成都春熙路美食攻略",
        cover: "/assets/img/message/mountain.png",
        author: "美食达人",
        collectTime: "2024-01-15 10:30",
        tags: ["美食", "春熙路", "成都"]
      },
      {
        id: 2,
        type: "shop",
        title: "老成都火锅",
        cover: "/assets/img/message/phone.png",
        author: "城旅达人",
        collectTime: "2024-01-14 16:20",
        tags: ["火锅", "美食", "推荐"]
      },
      {
        id: 3,
        type: "activity",
        title: "周末徒步活动",
        cover: "/assets/img/message/draw.png",
        author: "户外俱乐部",
        collectTime: "2024-01-13 20:15",
        tags: ["户外", "徒步", "活动"]
      }
    ],
    categories: [
      { name: "全部", active: true },
      { name: "攻略", active: false },
      { name: "商家", active: false },
      { name: "活动", active: false }
    ]
  },

  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '我的收藏'
    })
  },

  onItemTap: function(e) {
    const item = e.currentTarget.dataset.item
    
    wx.showModal({
      title: item.title,
      content: `作者：${item.author}\n收藏时间：${item.collectTime}\n标签：${item.tags.join('、')}`,
      showCancel: true,
      cancelText: '关闭',
      confirmText: '查看详情',
      success: function(res) {
        if (res.confirm) {
          wx.showToast({
            title: '详情页面开发中',
            icon: 'none'
          })
        }
      }
    })
  },

  onCategoryTap: function(e) {
    const index = e.currentTarget.dataset.index
    const categories = this.data.categories.map((item, i) => {
      item.active = i === index
      return item
    })
    this.setData({ categories })
    
    wx.showToast({
      title: '筛选：' + categories[index].name,
      icon: 'none'
    })
  }
})
